<script lang="ts" setup>
import { reactive, ref, onMounted, watch } from "vue";
import { FormInst } from "naive-ui";
import loginFormConfig from "./config";
import { useUserStore } from "@/store/modules/user";
import { useRouter } from "vue-router";
import { formatDate } from "@/utils/lib/date";
const router = useRouter();
const userStore = useUserStore();


const formRef = ref<FormInst | null>(null);
const login = async () => {
	try {
		const instance: Record<string, any> = formRef?.value?.getFormRef();
		const res = await userStore.login({
			account: instance.model.account,
			password: instance.model.password,
			login_time: formatDate(new Date()),
		});
		if (res.data.code === 200) {
			await userStore.getInfo({
				user_id:instance.model.account
			})
			router.push("/thing/index");
		}
	} catch (error) {
		return Promise.reject(error);
	}
};
</script>

<template>
	<Form :config="loginFormConfig" ref="formRef" />
	<n-button v-debounce="login" type="info" class="btn">登录</n-button>
</template>

<style lang="less" scoped>
@import "@/styles/mixin.less";
.btn {
	width: 277px;
}
</style>
